<template>
  <div class="mod-menu">
    <el-form :inline="true" :model="params">
      <el-form-item label="订单编号">
        <el-input
          v-model="params.order_code"
          placeholder="订单编号"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="交易单号">
        <el-input
          v-model="params.pay_order_code"
          placeholder="交易单号"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item label="订单状态">
        <el-select
          v-model="params.transaction_status"
          clearable
          placeholder="订单状态"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用户手机号码">
        <el-input
          v-model="params.mobile"
          placeholder="用户手机号码"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" row-key="Id" border style="width: 100%">
      <!-- <el-table-column prop="shop_name" align="center" label="商家名称">

      </el-table-column> -->
      <el-table-column prop="name" align="center" label="商品信息">
        <template slot-scope="scope">
          　　　　<el-popover placement="top-start" trigger="hover">
            <a
              :href="scope.row.child_order_list[0].goods_img"
              target="_blank"
              title="查看最大化图片"
              ><img
                :src="scope.row.child_order_list[0].goods_img"
                style="width: 300px; height: 300px"
            /></a>
            <img
              slot="reference"
              :src="scope.row.child_order_list[0].goods_img"
              @click="$openImg(scope.row.child_order_list[0].goods_img)"
              style="width: 50px; height: 50px; cursor: pointer"
            />
          </el-popover>
          {{ scope.row.child_order_list[0].goods_title }}
          　　</template
        >
      </el-table-column>
      <el-table-column
        prop="child_order_list[0].original_real_price"
        align="center"
        label="实收金额"
        width="120px"
      >
      </el-table-column>
      <el-table-column
        prop="service_order_contacts"
        align="center"
        label="客户信息"
      >
        <template slot-scope="scope">
          <div>
            {{
              scope.row.service_order_contacts &&
              scope.row.service_order_contacts.contacts
            }}
          </div>
          <div>
            {{
              scope.row.service_order_contacts &&
              scope.row.service_order_contacts.mobile
            }}
          </div>
        </template>
      </el-table-column>

      <el-table-column
        prop="pay_mode,format_pay_time,order_code,pay_order_code"
        align="center"
        label="支付信息"
      >
        <template slot-scope="scope">
          <div>
            支付方式 ：
            <span v-if="scope.row.pay_mode == 0">余额支付</span>
            <span v-if="scope.row.pay_mode == 1">微信支付</span>
            <span v-if="scope.row.pay_mode == 2">支付宝支付</span>
            <span v-if="scope.row.pay_mode == 3">银行线下支付</span>
            <span v-if="scope.row.pay_mode == 4">现金支付</span>
            <span v-if="scope.row.pay_mode == 5">积分支付</span>
            <span v-if="scope.row.pay_mode == 6">积分 + 余额 支付</span>
            <span v-if="scope.row.pay_mode == 7">积分 + 微信 支付</span>
            <span v-if="scope.row.pay_mode == 8">积分 + 支付宝 支付</span>
            <span v-if="scope.row.pay_mode == 9">公益积分支付</span>
            <span v-if="scope.row.pay_mode == 10">支付宝支付(Adapay)</span>
            <span v-if="scope.row.pay_mode == 12">支付宝支付(慧收钱)</span>
            <span v-if="scope.row.pay_mode == 14">银行卡支付</span>
            <!-- {{
              scope.row.pay_mode == 0
                ? '余额'
                : scope.row.pay_mode == 1
                ? '微信'
                : '支付宝'
            }} -->
          </div>
          <div>支付时间 ：{{ scope.row.format_pay_time }}</div>
          <div>订单编号 ：{{ scope.row.order_code }}</div>
          <div>交易单号 ：{{ scope.row.pay_order_code }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="transaction_status"
        align="center"
        label="订单状态"
        width="80px"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.payment_status == 6">支付过期</div>
          <div v-if="scope.row.transaction_status == 0">待支付</div>
          <div v-if="scope.row.transaction_status == 5">交易完成</div>
          <div v-if="scope.row.transaction_status == 6">交易关闭</div>
          <div
            v-if="
              scope.row.transaction_status == 1 ||
              scope.row.transaction_status == 2 ||
              scope.row.transaction_status == 3 ||
              scope.row.transaction_status == 4
            "
          >
            待使用
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="child_order_list[0].service_card.use_count"
        align="center"
        label="已使用次数"
      >
      </el-table-column>
      <el-table-column
        prop="child_order_list[0].service_card.residue_use_count"
        align="center"
        label="剩余次数"
      >
      </el-table-column>
      <el-table-column
        prop="format_expired_time"
        align="center"
        label="过期时间"
      >
      </el-table-column>
      <el-table-column
        prop="child_order_list[0].service_card.service_goods_use_status"
        align="center"
        label="可使用状态"
      >
        <template slot-scope="scope">
          <template v-if="scope.row.child_order_list[0].service_card">
            <el-tag
              v-if="
                scope.row.child_order_list[0].service_card
                  .service_goods_use_status == 4
              "
              >未支付不可用</el-tag
            >
            <el-tag
              v-if="
                scope.row.child_order_list[0].service_card
                  .service_goods_use_status == 0
              "
              >可使用</el-tag
            >
            <el-tag
              type="success"
              v-if="
                scope.row.child_order_list[0].service_card
                  .service_goods_use_status == 1
              "
              >已过期</el-tag
            >
            <el-tag
              type="info"
              v-if="
                scope.row.child_order_list[0].service_card
                  .service_goods_use_status == 2
              "
              >已完成</el-tag
            >
          </template>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        label="操作"
        width="80px"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="viewHandle(scope.row)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="params.page"
      :page-sizes="[10, 20, 30, 50]"
      :page-size="params.limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <el-dialog
      :title="`订单详情`"
      top="5vh"
      :visible.sync="dialogVisible"
      width="60%"
    >
      <orderDetail ref="orderDetail"></orderDetail>
    </el-dialog>
    <!-- 弹窗, 新增 / 修改 -->
    <!-- <view-or-update v-if="addOrUpdateVisible" ref="viewOrUpdate"></view-or-update> -->
  </div>
</template>

<script>
// import ViewOrUpdate from './view-or-update'
import orderService from '@/api/orderService.js'
import orderDetail from '../../merchant/order/serviceOrderDetail'

export default {
  data() {
    return {
      typeSelection: 1,
      dataList: [],
      dataListLoading: false,
      addOrUpdateVisible: false,
      options: [
        {
          value: 0,
          label: '待支付'
        },
        {
          value: 3,
          label: '待使用'
        },
        {
          value: 5,
          label: '交易完成'
        },
        {
          value: 6,
          label: '交易关闭'
        }
      ],
      params: {
        page: 1,
        limit: 10
      },
      total: 0,
      info: null,
      dialogVisible: false
    }
  },
  components: {
    orderDetail
    // ViewOrUpdate
  },
  created() {
    this.loadList()
  },
  methods: {
    viewHandle(item) {
      this.info = item
      this.dialogVisible = true
      orderService.platformOrderInfo(item.id).then((res) => {
        if (res.data && res.data.code == 200) {
          this.$refs.orderDetail.init(res.data.data)
        }
      })
    },
    handleSizeChange(e) {
      this.params.limit = e
      this.params.page = 1
      this.loadList()
    },
    handleCurrentChange(e) {
      this.params.page = e
      this.loadList()
    },
    getDataList() {
      this.params.page = 1
      this.loadList()
    },
    async loadList() {
      this.tableLoading = true

      let res = await orderService.saleOrderAll(this.params)

      if (res.data && res.data.code == 200) {
        this.dataList = res.data.page.list
        this.total = res.data.page.totalCount
      }
      this.tableLoading = false
    },

    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.viewOrUpdate.init(id)
      })
    }
  }
}
</script>
<style lang="scss">
.mb30 {
  margin-bottom: 30px;
}
</style>
